from rest_framework import serializers
from doubangroup.models import Group


# class GroupSerializer(serializers.Serializer):
#     groupname = serializers.CharField()
#     url = serializers.URLField()
#     enabled = serializers.BooleanField()
#
#     def create(self, validated_data):
#         return Group.objects.create(**validated_data)
#
#     def update(self, instance, validated_data):
#         instance.groupname = validated_data.get('groupname', instance.groupname)
#         instance.url = validated_data.get('url', instance.url)
#         instance.enabled = validated_data.get('enabled', instance.enabled)
#         instance.save()
#         return instance


class GroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = ('id', 'groupname', 'url', 'enabled')